<script>
	export default {
		globalData: {
			globalBottom: 0,
			loginNow: false, //标记是否正在登录页面，如果是，则不重复打开
		},
		onLaunch: function(options) {
			this.$app.update(); //更新
			if (options.query.scene) {
				let arr = options.query.scene.split('_')
				if (arr[0] == 'recomm') {
					uni.setStorageSync("recommender", arr[1]);
				} else if (arr[0] == 'channel') {
					uni.setStorageSync("channel", arr[1]);
				}
			}
			if (options.query.relation) {
				uni.setStorageSync('relation', options.query.relation)
			}
			this.checkSession()

			let _this = this;
			uni.getSystemInfo({
				success(res) {
					if (res.safeArea.top > 20) {
						_this.globalData.globalBottom = res.safeArea.top - 20 - 14	//兼容屏幕黑边 20为固定值
					}
				}
			})
		},
		onShow: function() {},
		onHide: function() {},
		methods: {
			async checkSession() {
				var _this = this
				let token = await this.$db.get('token');
				let [overTime, session] = await uni.checkSession();
				if (token && !overTime) {
					return
				};
				if (token && overTime) {
					uni.showModal({
						title: '登陆提醒',
						content: '您的登陆信息已失效，请问是否重新登陆？',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/login/login'
								})
								return false
							}
							_this.$db.remove('token')
						}
					})
				}
			},
		},
		computed: {}
	};
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
	page {
		background: #fff;
		font-size: 26rpx;
		color: #333333;
	}

</style>
